package com.gjs.cd.controller;

import com.gjs.cd.pojo.vo.CodeVo;
import com.gjs.cd.service.ICodeService;
import com.gjs.common.exception.BizException;
import com.gjs.common.manager.response.RspBody;
import com.gjs.common.pojo.dto.request.PageQuery;
import com.gjs.common.pojo.dto.response.ListPageRsp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api(tags = "光盘激活码接口")
@RequestMapping("/code1")
@RequiredArgsConstructor

public class CodeController {

    private ICodeService iCodeService;



    @GetMapping("/test")
    @ApiOperation("测试接口")
    public RspBody<String> test(String name){
        return RspBody.success("测试接口:"+name);
    }


    @ApiOperation("新增激活码")
    @GetMapping("/add")
    public RspBody<Integer> add(Long batchId,int num){
        if (batchId==0 || num < 1){
            throw new BizException("批次或数量不能为空");
        }
        return RspBody.success(iCodeService.add(batchId,num));
    }

    @ApiOperation("查询批次分页列表数据")
    @GetMapping("/list")
    public RspBody<ListPageRsp<CodeVo>> list(PageQuery pageQuery,Integer batchId){
        return RspBody.success(ListPageRsp.of(iCodeService.queryBatch(pageQuery,Long.parseLong(batchId.toString()))));
    }

}
